<?php

namespace App\Http\Controllers\Api\Meeting;

use App\Http\Controllers\Controller;
use App\Models\MeetingGuest;
use App\Models\MeetingSignin;
use Illuminate\Http\Request;

class SigninController extends Controller
{
    public function signin(Request $request)
    {
        $code = $request->input('code');
        if ($guest = MeetingGuest::findByCode($code)) {
            MeetingSignin::create([
                'guest_id' => $guest->id,
                'longitude' => $request->input('longitude'),
                'latitude' => $request->input('latitude'),
                'address' => $request->input('address')
            ]);
            $guest->load(['group']);
            return ajaxReturn(['guest' => $guest]);
        } else {
            return ajaxError(500, '您输入的邀请码无效');
        }
    }
}
